package com.huaxin.hxmoduleworkorder.controller;

import com.huaxin.hxmoduleworkorder.common.annotation.validation.ValidCustomerType;
import com.huaxin.hxmoduleworkorder.dto.ResponseResult;
import com.huaxin.hxmoduleworkorder.dto.request.InspectionTemplateItemRelCreateReqDTO;
import com.huaxin.hxmoduleworkorder.models.InspectionTemplateItem;
import com.huaxin.hxmoduleworkorder.models.InspectionTemplateItemRel;
import com.huaxin.hxmoduleworkorder.service.InspectionTemplateItemRelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "模版与模版项的关联")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/workorder/inspectionTemplateItemRel")
public class InspectionTemplateItemRelController {
    private final InspectionTemplateItemRelService inspectionTemplateItemRelService;

    @Operation(summary = "添加", description = "添加")
    @PostMapping("/create")
    public ResponseResult<InspectionTemplateItemRel> create(@RequestBody InspectionTemplateItemRelCreateReqDTO in) {
        return inspectionTemplateItemRelService.create(in);
    }

    @Operation(summary = "根据模版id和模版项id删除", description = "根据模版id和模版项id删除")
    @DeleteMapping("/delete")
    public ResponseResult<String> delete(@Parameter(description = "模版ID", name = "templateId") @RequestParam(name = "templateId", required = true) String templateId,
                                         @Parameter(description = "模版项ID", name = "templateItemId") @RequestParam(name = "templateItemId", required = true) String templateItemId) {
        return inspectionTemplateItemRelService.delete(templateId, templateItemId);
    }

    @Operation(summary = "根据模板ID查询", description = "根据模板ID查询")
    @GetMapping("/listByTemplateId")
    public ResponseResult<List<InspectionTemplateItem>> listByTemplateId(@Parameter(description = "模版ID", name = "templateId") @RequestParam(name = "templateId", required = true) String templateId,
                                                                         @Parameter(description = "客户类型，为Null或空时查询模板的所有模板项", name = "customerType") @RequestParam(name = "customerType", required = false) @ValidCustomerType String customerType) {
        return inspectionTemplateItemRelService.listByTemplateId(templateId, customerType);
    }

    @Operation(summary = "根据模板ID删除", description = "根据模板ID删除")
    @DeleteMapping("/deleteByTemplateId")
    public ResponseResult<String> deleteByTemplateId(@Parameter(description = "模版ID", name = "templateId") @RequestParam(name = "templateId", required = true) String templateId) {
        return inspectionTemplateItemRelService.deleteByTemplateId(templateId);
    }

    @Operation(summary = "根据变电箱类型查询", description = "根据变电箱类型查询")
    @GetMapping("/listByCabinetType")
    public ResponseResult<List<InspectionTemplateItem>> listByCabinetType(@Parameter(description = "变电箱类型", name = "cabinetType") @RequestParam(name = "cabinetType", required = true) String cabinetType) {
        return inspectionTemplateItemRelService.listByCabinetType(cabinetType);
    }

    @Operation(summary = "根据变电箱类型删除", description = "根据变电箱类型删除")
    @DeleteMapping("/deleteByCabinetType")
    public ResponseResult<String> deleteByCabinetType(@Parameter(description = "变电箱类型", name = "cabinetType") @RequestParam(name = "cabinetType", required = true) String cabinetType,
                                                      @Parameter(description = "模板项ID，不传时会删除变电箱类型关联的所有模板项", name = "templateItemId") @RequestParam(name = "templateItemId", required = false) String templateItemId) {
        return inspectionTemplateItemRelService.deleteByCabinetType(cabinetType, templateItemId);
    }

    @Operation(summary = "根据关联ID删除", description = "根据关联ID删除")
    @DeleteMapping("/deleteByRelId")
    public ResponseResult<String> deleteByRelId(@Parameter(description = "关联ID", name = "relId") @RequestParam(name = "relId", required = true) String relId) {
        return inspectionTemplateItemRelService.deleteByRelId(relId);
    }

    @Operation(summary = "检查设备类型是否存在")
    @GetMapping("/existsByCabinetType")
    public ResponseResult<Boolean> existsByCabinetType(@Parameter(description = "设备类型") @RequestParam(name = "cabinetType", required = true) String cabinetType) {
        return inspectionTemplateItemRelService.existsByCabinetType(cabinetType);
    }
}
